import Vue from 'vue'

import Cookies from 'js-cookie'

import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/ruoyi.scss' // ruoyi css
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive
import plugins from './plugins' // plugins
import { download } from '@/utils/request'

import './assets/icons' // icon
import './permission' // permission control
import currency from 'currency.js'
import _ from 'lodash'
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi";

import VueMeta from 'vue-meta'
import TheQueryForm from '@/components/TheQueryForm/index.vue'
import TheTable from '@/components/TheTable/index.vue'
import TheCreateForm from "@/components/TheCreateForm";

// 字典数据组件
import moment from "moment";
import * as utils from '@/utils/index'
import Json2Excel from '@/utils/Json2Excel.js'
import numFmt from '@/utils/xlsx-style-numFmt.js'
import config from '/public/config.js'
import * as filters from './filters' // global filters
import { transNumber } from "@/utils/numberTrans";
import VueAMap from 'vue-amap'; //引入高德地图
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: '4714b27b49d825e47a442a0d76a9c95d',
  plugin: [ // 这里根据自己项目按需引入插件
    'AMap.Autocomplete',
    'AMap.PlaceSearch',
    'AMap.Scale',
    'AMap.OverView',
    'AMap.ToolBar',
    'AMap.MapType',
    'AMap.PolyEditor',
    'AMap.CircleEditor',// 圆形编辑器插件
    "AMap.Geolocation", // 定位控件，用来获取和展示用户主机所在的经纬度位置
    "AMap.Geocoder", // 地理编码与逆地理编码服务，用于地址描述与坐标间的相互转换
    "AMap.CitySearch",
    'AMap.Marker',
  ]
});
window._AMapSecurityConfig = {
  securityJsCode: '228419df8151477cf6c50c2ce131bc89',
}
// 解决高德地图刷新显示不出来
const amapKeys = Object.keys(localStorage).filter(key => key.match(/^_AMap_/))
amapKeys.forEach(key => { localStorage.removeItem(key) })
// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree


Vue.use(directive)
Vue.use(plugins)
Vue.use(VueMeta)
moment.suppressDeprecationWarnings = true; // 关闭警告
Vue.prototype.$moment = moment;
Vue.prototype.$transNum = transNumber; // 数
Vue.prototype.$filters = filters; // 数
Vue.prototype.$utils = utils

window.$Json2Excel = Json2Excel
window.$numFmt = numFmt
Vue.component('TheQueryForm', TheQueryForm)
Vue.component('TheTable', TheTable)
Vue.component('TheCreateForm', TheCreateForm)

window.config = config
Vue.directive('column-domItem-show', {
  //当指令[第一次]被绑定到元素上的时候，会立即触发 bind函数
  //形参中的el 表示当前指令所绑定到的那个DOM对象---指令所在元素
  bind(el, binding) {
    el.style.display = binding.value ? "" : "none";
  },
  //每次DOM更新时被调用
  update(el, binding) {
    el.style.display = binding.value ? "" : "none";
  }
})

// precision指代精确到小数点哪一位，可选0，1，2…
// symbol则是数字前的符号，一般配置货币符号
// decimal选项是配置小数点那一位的符号（替换小数点）
// separator指代分隔符，按照三位数一个分隔符来格式化
// scale 缩放倍数
Number.prototype.tranFormat = function (precision, scale, flag = false, symbol = "￥", separator = ',') {
  let num = this ? Number(this + '') : 0
  if (!_.isNumber(num)) {
    num = 0
  }
  if (_.isNumber(scale)) {
    if (scale >= 1) {
      num = _.multiply(num, Math.pow(10, scale))
    } else {
      num = _.divide(num, Math.pow(10, Math.abs(scale)))
    }
  }
  return currency(num, { precision, symbol: flag ? symbol : '', separator: flag ? separator : '' }).format()
}
Number.prototype.tranAdd = function (...args) {
  let num = Number(this + '')
  return args.reduce((prev, cur) => currency(prev).add(cur).value, num)
}
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})
// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
